namespace DotNetNuke.Common.Utilities
{
    using DotNetNuke.Services.Localization;
    using DotNetNuke.UI.Utilities;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Globalization;
    using System.Web.UI.WebControls;

    public class Calendar
    {
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Opens a popup Calendar
        /// </summary>
        /// <param name="Field">TextBox to return the date value</param>
        /// <returns></returns>
        /// <remarks>
        /// </remarks>
        /// <history>
        /// [VMasanas]	12/09/2004	Added localized parameter strings: today, close, calendar
        /// Use AbbreviatedDayName property instead of first 3 chars of day name
        /// [VMasanas]	14/10/2004	Added support for First Day Of Week
        /// [VMasanas]  14/11/2004  Register client script to work with FriendlyURLs
        /// </history>
        /// -----------------------------------------------------------------------------
        public static string InvokePopupCal(TextBox Field)
        {
            char[] TrimChars = new char[] { ',', ' ' };
            string MonthNameString = "";
            foreach (string Month in DateTimeFormatInfo.CurrentInfo.MonthNames)
            {
                MonthNameString = MonthNameString + Month + ",";
            }
            MonthNameString = MonthNameString.TrimEnd(TrimChars);
            string DayNameString = "";
            foreach (string Day in DateTimeFormatInfo.CurrentInfo.AbbreviatedDayNames)
            {
                DayNameString = DayNameString + Day + ",";
            }
            DayNameString = DayNameString.TrimEnd(TrimChars);
            string FormatString = DateTimeFormatInfo.CurrentInfo.ShortDatePattern.ToString();
            if (!ClientAPI.IsClientScriptBlockRegistered(Field.Page, "PopupCalendar.js"))
            {
                ClientAPI.RegisterClientScriptBlock(Field.Page, "PopupCalendar.js", "<script src=\"" + ClientAPI.ScriptPath + "PopupCalendar.js\"></script>");
            }
            return ("javascript:popupCal('Cal','" + Field.ClientID + "','" + FormatString + "','" + MonthNameString + "','" + DayNameString + "','" + DotNetNuke.Services.Localization.Localization.GetString("Today") + "','" + DotNetNuke.Services.Localization.Localization.GetString("Close") + "','" + DotNetNuke.Services.Localization.Localization.GetString("Calendar") + "'," + Conversions.ToString((int) DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek) + ");");
        }
    }
}

